# Contributor: omni <omni+alpine@hack.org>
# Maintainer: omni <omni+alpine@hack.org>
pkgname=arti
pkgver=1.1.11
pkgrel=0
pkgdesc="An implementation of Tor, in Rust"
url="https://docs.rs/arti/latest/arti/"
license="GPL-3.0-or-later"
# ppc64le & s390x blocked by ring crate
arch="all !ppc64le !s390x !riscv64"
makedepends="cargo openssl-dev>3 sqlite-dev zstd-dev xz-dev cargo-auditable"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://gitlab.torproject.org/tpo/core/arti/-/archive/arti-v$pkgver/arti-arti-v$pkgver.tar.gz
	disable_system_time_conversion_patch
	"
builddir="$srcdir/$pkgname-$pkgname-v$pkgver"


prepare() {
	default_prepare
	cargo fetch --target="$CTARGET" --locked

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided libs
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		zstd = { rustc-link-lib = ["zstd"] }
	EOF

	case "$CARCH" in
	arm*|x86)
		patch crates/tor-hsservice/src/time_store.rs \
		"$srcdir"/disable_system_time_conversion_patch
		;;
	esac
}

build() {
	cargo auditable build --release --frozen --bin arti
}

check() {
	cargo test --frozen
}

package() {
	install -Dm755 -t "$pkgdir"/usr/bin/ target/release/arti
	install -Dm755 -t "$pkgdir"/usr/share/doc/"$pkgname"/ \
		doc/bridges.md doc/Compatibility.md doc/FAQ.md doc/SupportPolicy.md \
		CHANGELOG.md README.md
}

sha512sums="
8b33c460e515ea87585c09c40141a85118ba5fa1e9ef89dd57ae19864d937159c2a6505055e85c5dda487623b15613a0ea5d2ac3406dac44b0ed895a98126d06  arti-1.1.11.tar.gz
4925f8e3d4b00e1d4ae5580c16f0ed71bed6fdcdacc64d6ff4a2fdfa46d3d8dd1542a61ca00c546ff4e4974ab47620b96429cda5c6804b6bdfaccf4d276f9662  disable_system_time_conversion_patch
"
